package com.itheima.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dto.OrderReturnDto;
import com.itheima.mapper.OmsOrderReturnApplyMapper;
import com.itheima.pojo.OmsOrderReturnApply;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class OmsOrderReturnApplyImpl implements OmsOrderReturnApplyApi{
    @Autowired
    private OmsOrderReturnApplyMapper mapper;

    @Override
    public List<OmsOrderReturnApply> findAll() {
        List<OmsOrderReturnApply> applies = mapper.selectList(new LambdaQueryWrapper<>());

        return applies;
    }
    @Autowired
    private OmsOrderReturnApplyMapper omsOrderReturnApplyMapper;


    @Override
    public void deletes(ArrayList<Integer> ids) {
        if (ObjectUtil.isNotNull(ids)){
            omsOrderReturnApplyMapper.deleteBatchIds(ids);
        }
    }

    @Override
    public OmsOrderReturnApply findById(Integer id) {
        OmsOrderReturnApply omsOrderReturnApply = omsOrderReturnApplyMapper.selectById(id);
        return omsOrderReturnApply;
    }

    @Override
    public void updateReturn(Integer id, OmsOrderReturnApply omsOrderReturnApply) {
        LambdaUpdateWrapper<OmsOrderReturnApply> wrapper=new LambdaUpdateWrapper<>();
        wrapper.eq(OmsOrderReturnApply::getId,id);
        omsOrderReturnApplyMapper.update(omsOrderReturnApply,wrapper);
    }

    @Override
    public IPage<OmsOrderReturnApply> list(OrderReturnDto orderReturnDto) {
        IPage<OmsOrderReturnApply> page = new Page<>(orderReturnDto.getPageNum(), orderReturnDto.getPageSize());
        LambdaQueryWrapper<OmsOrderReturnApply> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(!ObjectUtil.isEmpty(orderReturnDto.getCreateTime()),OmsOrderReturnApply::getCreateTime,orderReturnDto.getCreateTime())
                .like(!ObjectUtil.isEmpty(orderReturnDto.getHandleMan()),OmsOrderReturnApply::getHandleMan,orderReturnDto.getHandleMan())
                .eq(!ObjectUtil.isEmpty(orderReturnDto.getHandleTime()),OmsOrderReturnApply::getCreateTime,orderReturnDto.getHandleTime())
                .eq(!ObjectUtil.isEmpty(orderReturnDto.getId()),OmsOrderReturnApply::getId,orderReturnDto.getId())
                .like(!ObjectUtil.isEmpty(orderReturnDto.getReceiverKeyword()),OmsOrderReturnApply::getReturnName,orderReturnDto.getReceiverKeyword())
                .like(!ObjectUtil.isEmpty(orderReturnDto.getReceiverKeyword()),OmsOrderReturnApply::getReturnPhone,orderReturnDto.getReceiverKeyword())
                .eq(!ObjectUtil.isEmpty(orderReturnDto.getStatus()),OmsOrderReturnApply::getStatus,orderReturnDto.getStatus())
                .eq(OmsOrderReturnApply::getStatus,0);
        omsOrderReturnApplyMapper.selectPage(page,wrapper);
        return page;
    }
}


